#!/usr/bin/env bash
pidfile=/var/run/mongo.pid
start(){
  echo -e 'start mongo service... ...'
  ./bin/mongod -f ./mongo.cnf
}

stop(){
  if test -e $pidfile 
  then
     echo -e 'stop mongo service... ...'
  	 kill -9 `cat $pidfile`
     echo -e 'stop mongo ok... ...'
 else
 	echo -e 'no mongo service... ...'
 fi
}

list(){
 ps aux | grep mongod
}

restart(){

	echo -e 'restart mongod service'
	stop
	start
}

create(){

  ./bin/mongoimport --db $1

}

case $1 in
         start)
                   start
        ;;
         stop)
        stop
        ;;
         restart)
        restart
        ;;
         list)
        list
        ;;
        create)
	     create
	      ;;
         *)
        echo "Usage: $SCRIPTNAME {create|start|stop|restart|list}" >&2
        exit 1
        ;;
esac
exit 0
